package individual.ircon.bilibili.bean;

/**
 * 帧的信息。
 */
public class DanmuDataFrame {
    public int PackageLength;
    public short HeadLength;
    public short Version;
    public int Category;
    public int Other;
    public byte[] Data;

    public DanmuDataFrame(){

    }

    /**
     * data不会拷贝。
     * @param package_length 包的长度
     * @param head_length 头的长度，固定为16
     * @param version 协议的版本
     * @param category 消息的类型
     * @param other 其他，固定为1
     * @param data 数据
     */
    public DanmuDataFrame(int package_length,
                          short head_length, short version,
                          int category, int other, byte[] data
    ){
        this.PackageLength = package_length;
        this.HeadLength = head_length;
        this.Version = version;
        this.Category = category;
        this.Other = other;
        this.Data = data;
    }

    /**
     * data不复制，自动计算了包的长度，自动设置了头的长度和字段“其他”。
     * @param version 协议版本
     * @param category 消息类型
     * @param data 数据
     */
    public DanmuDataFrame(short version, int category, byte[] data) {
        this.PackageLength = data.length + 16;
        this.HeadLength = 16;
        this.Version = version;
        this.Category = category;
        this.Data = data;
    }

    @Override
    public String toString() {
        return "DataFrame{" +
                "PackageLength=" + PackageLength +
                ", HeadLength=" + HeadLength +
                ", Version=" + Version +
                ", Category=" + Category +
                ", Other=" + Other +
                ", DataLength=" + Data.length +
                '}';
    }
}
